package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.erp.activity.MainKActivity

import com.erp.bean.ProductionBean
import com.erp.R
import kotlinx.android.synthetic.main.lv_production_item.view.*

/**
 * Created by Administrator on 2016/11/21/021.
 * 作者：刘洋
 */
class OrderProductionAdapter(private val mlist: List<ProductionBean>, private val mcontext: Context) : BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)

    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(i: Int): Any {
        return mlist[i]
    }

    override fun getItemId(i: Int): Long {
        return i.toLong()
    }

    override fun getView(i: Int, view: View?, viewGroup: ViewGroup?): View {
        var v : View
        var vh: ViewHolder
        if (view == null) {
            v = minflater.inflate(R.layout.lv_production_item, null)
            vh = ViewHolder(v)
            v.tag = vh
        } else {
            v = view
            vh = v.tag as ViewHolder
        }
        var productionBean = mlist[i]
        settv(vh.tv0, productionBean.onum)
        settv(vh.tv1, productionBean.ot_name)
        settv(vh.tv2, productionBean.content_description)
        settv(vh.tv3, productionBean.customer)
        settv(vh.tv4, productionBean.tel)
        settv(vh.tv5, productionBean.contract_num)
        settv(vh.tv6, productionBean.shop_name)
        if (productionBean.special_status.equals("5")) {
            settv(vh.tv7, "已取消")
        } else if (productionBean.special_status.equals("0")) {
            settv(vh.tv7, "")
        }
        if(MainKActivity.ZhuanMaiDianid=="0"){
            vh.LlTeFu.visibility=View.VISIBLE
            settv(vh.TvTeFu,productionBean.special_service_cat)
        }else{
            vh.LlTeFu.visibility=View.GONE
        }
        return v
    }

    private fun settv(tv: TextView, s: String) {
        if (s == "null") {
            tv.text = ""
        } else {
            tv.text = s
        }
    }

    private class ViewHolder(v : View) {
        val tv0 = v.tv_production_0
        val tv1 = v.tv_production_1
        val tv2 = v.tv_production_2
        val tv3 = v.tv_production_3
        val tv4 = v.tv_production_4
        val tv5 = v.tv_production_5
        val tv6 = v.tv_production_6
        val tv7 = v.tv_production_7
        val LlTeFu = v.LlTeFu
        val TvTeFu = v.tvTeFu
    }
}
